package com.sand.controller;

import com.sand.dto.Select.UserSelect;
import com.sand.dto.merchant.merchantDto;
import com.sand.result.ResponseResult;
import com.sand.service.MerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sand.dto.merchant.AddMerchant;

@RestController
@RequestMapping("/merchant")
public class MerchantController {


    @Autowired
    private MerchantService merchantService;


    /**
     * 新增商家(完成)
     */
    @PostMapping("/add")
    public ResponseResult<String> addMerchant( @RequestBody AddMerchant addMerchant){
        String i =  merchantService.add(addMerchant);
        return new ResponseResult<String>().okResult(i);
    }

    //修改商家权限
    @PostMapping("/UpdatePermission")
    public ResponseResult<String> UpdatePermission(@RequestBody Integer id){
        String str =  merchantService.UpdatePermission(id);
        return new ResponseResult<String>().hint(str);
    }


    //根据查询商家(完成)
    @PostMapping("/select")
    public ResponseResult<merchantDto> select(@RequestBody UserSelect userSelect){
        merchantDto merchantDto = merchantService.select(userSelect);
        return new ResponseResult<merchantDto>().okResult(merchantDto);
    }

    //根据商家id查询商家的权限(完成)
    @PostMapping("/permission")
    public ResponseResult<Integer> permission(@RequestBody Integer id){
        Integer permission =  merchantService.permission(id);
        return new ResponseResult<Integer>().okResult(permission);
    }

}
